﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_ListUsers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Command_DeleteUser(Object sender, CommandEventArgs e)
    {
        if (e.CommandArgument != null)
        {
            string id = (string)e.CommandArgument;
            if (id == "admin")
            {
                ErrorText.Text = "不能删除管理员用户。";
            }
            else if (id.Equals(Session["Current_User_Id"]))
            {
                ErrorText.Text = "不能删除当前用户。";
            }
            else if (!"admin".Equals(Session["Current_User_Id"]))
            {
                ErrorText.Text = "无权执行删除操作。";
            }
            else
            {
                TreasurerDataContext db = new TreasurerDataContext();
                var q = from aA in db.Articles
                        where aA.ID == id
                        select aA;
                db.Articles.DeleteAllOnSubmit(q);
                db.SubmitChanges();

                Response.Write("<script>alert('所选文章信息已经被成功删除。');document.location='ListArticles.aspx';</script>");
            }
        }
    }
    protected void NewUserButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Manage/EditUser.aspx");
    }
}